<?php
class  Testimonial extends Vnf_Db_Table{
    protected $_name;
    protected $_primary = 'testimonialID';

    function __construct() {
        $this->_name = DB_PREFIX . "testimonial";
        parent::__construct(); 
    }

    public function getColumns() {
        $results = array('testimonialID', 'customerID', 'fullname', 'city', 'state', 'description', 'date', 'activeYN', 'Staff');
    }

    public function getPrimaryKey() {
        $pk = $this->_primary;
        if (is_array($pk)) {
            if (count($pk) > 0)
                return $pk[1]; // array[1] contain column name of primary key
        }
        return $this->_primary;
    }
    
    public function getRecords($where = null, $order = null, $count = null, $offset = 0) {
        $table_name = $this->_name;
        $primary_key = $this->getPrimaryKey();
        $select = Zend_Db_Table_Abstract::select();
        $select->setIntegrityCheck(false)
            ->from(array('thistable' => $table_name))
            ->joinLeft( array( 'f0table' => DB_PREFIX . "customer"), "thistable.customerID = f0table.CustomerNo", array('CustomerNo', 'LastName', 'FirstName','City', 'State'))
           ;
        if($where) {
            $select->where($where);
        }
        if($order) {
            $select->order($order);
        }
        if($count)
            $select->limit($count, $offset);
        $data = $this->fetchAll($select);
        return $data;
    }
    
    public function avg($where) {
        $select = Zend_Db_Table_Abstract::select();
        $select->from(array('thistable' => $this->_name), array('avg' => "avg(`level`)"));
        if ($where) {
            $select->where($where);
        }

        $result = 0;
        $data = $this->fetchRow($select);
        @$result = $data->avg;

        return $result;
    }
}